package com.ysd.lis.controller.self;


import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.slef.SelfFunction;
import com.ysd.lis.request.DeleteParam;
import com.ysd.lis.service.self.SelfFunctionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wh
 * @since 2025-05-12
 */
@RestController
@RequestMapping("/self/function")
public class SelfFunctionController extends BaseController {

    @Autowired
    private SelfFunctionService selfFunctionService;

    @ApiOperation("查询")
    @GetMapping("/findFunctionList")
    public Result findFunctionList(SelfFunction selfFunction) {
        return selfFunctionService.findFunctionList(selfFunction);
    }


    @ApiOperation("添加功能")
    @PostMapping("/addFunction")
    public Result addFunction(@RequestBody SelfFunction selfFunction) {
        return selfFunctionService.addFunction(selfFunction);
    }

    @ApiOperation("编辑功能")
    @PostMapping("/editFunction")
    public Result editFunction(@RequestBody SelfFunction selfFunction) {
        return selfFunctionService.editFunction(selfFunction);
    }


    @ApiOperation("删除功能")
    @PostMapping("/deleteFunction")
    public Result deleteFunction(@RequestBody DeleteParam deleteParam) {
        boolean b = selfFunctionService.removeByIds(Arrays.asList(deleteParam.getIds().split(",")));
        if (b) {
            return Result.succ(1, "删除成功", "");
        }
        return Result.fail("删除失败");
    }
}
